# Contributor (MSYS2): David Macek <david.macek.0@gmail.com>
# Maintainer (Arch Linux): Alexander Rødseth <rodseth@gmail.com>
# Contributor (Arch Linux): Angel 'angvp' Velasquez <angvp[at]archlinux.com.ve>
# Contributor (Arch Linux): djgera
# Contributor (Arch Linux): Patrick Melo <patrick@patrickmelo.eti.br>

_realname=geany-plugins
_realpkgver=2.0.0
pkgbase="mingw-w64-${_realname}"
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=${_realpkgver%.*}
pkgrel=3
pkgdesc='Plugins for Geany (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://plugins.geany.org/'
msys2_repository_url="https://github.com/geany/geany-plugins"
msys2_references=(
  'archlinux: geany-plugins'
)
license=('spdx:GPL-2.0-or-later AND GPL-3.0-or-later AND BSD-2-Clause')
depends=("${MINGW_PACKAGE_PREFIX}-geany>=${pkgver}"
         "${MINGW_PACKAGE_PREFIX}-discount"
         "${MINGW_PACKAGE_PREFIX}-gtkspell3"
         "${MINGW_PACKAGE_PREFIX}-ctpl"
         "${MINGW_PACKAGE_PREFIX}-gpgme"
         "${MINGW_PACKAGE_PREFIX}-lua51"
         "${MINGW_PACKAGE_PREFIX}-gtk3"
         "${MINGW_PACKAGE_PREFIX}-libgit2"
         "${MINGW_PACKAGE_PREFIX}-gtk-update-icon-cache"
         "${MINGW_PACKAGE_PREFIX}-hicolor-icon-theme")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-vala"
             'intltool')
#             "${MINGW_PACKAGE_PREFIX}-cppcheck")
# optdepends=("${MINGW_PACKAGE_PREFIX}-hspell: hebrew spell checker")
source=("https://github.com/geany/geany-plugins/releases/download/${_realpkgver}/${_realname}-${pkgver}.tar.bz2"
        "https://github.com/geany/geany-plugins/commit/bb289f1562ec4368efa400c3d17cb17c206f101d.patch"
        "https://github.com/geany/geany-plugins/commit/07f0fdc1ef2ccaf104b5f9591bfcf3a56f035c4f.patch")
sha256sums=('9fc2ec5c99a74678fb9e8cdfbd245d3e2061a448d70fd110a6aefb62dd514705'
            '11d2271d90a998f6591cbebc84c369f2de14d6108d2f4e78eff86ed2e9262964'
            '65346c504b3a93988aa683933fa9dc16c5e245268a9bfbb5d47af5b6c0c36044')

apply_patch_with_msg() {
  for _patch in "$@"
  do
    msg2 "Applying ${_patch}"
    patch -Nbp1 -i "${srcdir}/${_patch}"
  done
}

prepare() {
  cd ${_realname}-${pkgver}

  apply_patch_with_msg \
    "bb289f1562ec4368efa400c3d17cb17c206f101d.patch" \
    "07f0fdc1ef2ccaf104b5f9591bfcf3a56f035c4f.patch"
}

build() {
  mkdir -p "build-${MSYSTEM}" && cd "build-${MSYSTEM}"

  export lt_cv_deplibs_check_method='pass_all'

  CFLAGS+=" -Wno-deprecated-declarations" \
  CXXFLAGS+=" -Wno-deprecated-declarations" \
  ../${_realname}-${pkgver}/configure \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --build=${MINGW_CHOST} \
    --prefix=${MINGW_PREFIX} \
    --libexecdir=${MINGW_PREFIX}/lib \
    --with-geany-libdir=${MINGW_PREFIX}/lib \
    --disable-static

  make
}

package() {
  cd "build-${MSYSTEM}"
  make DESTDIR="${pkgdir}" install
}
